<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%-- 引入页面头 --%>
<%@ include file="/pageHead.jsp"%>

<form name="form1" id="form1" action="" method="post">
	<div class="pageMain">
		<div class="pageTitle"><%=MessageResourcesUtils.getMessage(request, "systemmanage.storemanagement.title") %>
		<span></span><%=MessageResourcesUtils.getMessage(request, "dailyoperation.storeChannel.title.channel") %><span></span>
		<%=MessageResourcesUtils.getMessage(request, "dailyoperation.storeChannel.title.channel.add") %></div>
		<div class="pageBody">
			<div class="form-group">
				<ul>
					<li>	
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.number") %></label>
						<span><input type="text" id="storecode" name="storenumber" class="validate[required]"/></span>
						<input type="hidden" id="storeid" name="storeid"  class="validate[required]">			
					</li>
					<li>
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.name") %></label>
						<span><input type="text" id="storename" name="storename" value="" readonly="readonly" /></span>
					</li>
				</ul>
				<ul>
					<li>	
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.storeChannel.column.url") %></label>
						<span><input type="text" id="url" name="url" maxlength="50" size="22" class="validate[required]" /></span>
					</li>
					<li>	
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.storeChannel.column.des") %></label>
						<span><input type="text" id="secretkey" name="secretkey" readonly="readonly" /></span>
					</li>
				</ul>
				<ul>
					<li>	
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.storeChannel.column.publickey") %></label>
						<span><input type="text" id="publickey" name="publickey" readonly="readonly"  class="validate[required]" /></span>
					</li>
					<li>	
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.storeChannel.column.privatekey") %></label>
						<span><input type="text" id="privatekey" name="privatekey" readonly="readonly" class="validate[required]"/></span>
					</li>
				</ul>			
			</div>
			<br/>			
        	<div class="button-group">
       			<input type="hidden"  name="updateposition" id="updateposition" value="0"/>
       			<input type="button" class="btn btn-default"  id="butCreate" name="butCreate" value='<%=MessageResourcesUtils.getMessage(request, "common.button.secret") %>' />
       			<input type="button" class="btn btn-default"  id="butSave" name="butSave" value='<%=MessageResourcesUtils.getMessage(request, "common.button.save") %>' />
       			<input type="button" class="btn btn-default"  id="butReturn" name="butReturn" value='<%=MessageResourcesUtils.getMessage(request, "common.button.back") %>' />
			</div>
		</div>
	</div>
</form>

<script type="text/javascript">	
$(document).ready(function() {
	$('#butSave').click(function() {
			var exp = $('#form1').validationEngine('validate');

			if(exp==true)
			{
				// 显示进度条
				showSending();
				$.ajax({
					type: 'POST',
				    url: '${systemctx}/dailyoperation/storechannel/validattionChannel.json',
				    data: $("#form1").serialize(),
				    dataType: 'json',
				    success: function(data)
				    {
				    	//关闭执行...
						closeSending();
				    	if (data.messagetype == '2')
				    	{
				    		//显示AJAX请求后的提示信息
							$.fn.ajaxmessage(data);
				    	}
				    	else
				    	{
				    		form1.action="${systemctx}/dailyoperation/storechannel/addChannel.web";
							form1.submit();
				    	}
				    }
				});
			}
	});
	
	$('#butCreate').click(function() {
		// 显示进度条
		showSending();
		$.ajax({
			type: 'POST',
		    url: '${systemctx}/dailyoperation/storechannel/createSecretKey.json',
		    data: $("#form1").serialize(),
		    dataType: 'json',
		    success: function(data)
		    {
		    	//关闭执行...
				closeSending();
		    	if (data.messagetype == '2')
		    	{
		    		//显示AJAX请求后的提示信息
					$.fn.ajaxmessage(data);
		    	}
		    	else
		    	{
		    		$("#secretkey").val(data.map.secretkey);
		    		$("#publickey").val(data.map.publickey);
		    		$("#privatekey").val(data.map.privatekey);
		    	}
		    }
		});
	});
	
	$('#butReturn').click(function(){
		parent.document.location.reload();
	    $.fn.closeIssWindow();
	});
	selectCurrency();
});

function selectCurrency(){
	$("#storecode").issNewMagnifier({
		title: '<%=MessageResourcesUtils.getMessage(request, "systemmanage.databasebinding.storemagnifiertitle") %>',
		url: '${systemctx}/publicMagnifier/publicMagnifier.json',
		sortName : 'modifytime',
		sortOrder : 'desc',
		linkName: 'number',
		callSqlKey: 'queryStoreMagnifierSql',
		changeIgnore: ['storecode'],
		columns: [[
				{title:'<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.number") %>', field:'number', width:180, sortable:true, align: 'left', formel:'storecode'},
				{title:'<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.name") %>', field:'name', sortable:true, align: 'left', formel:'storename'},
		       	{field:'id', hidden:true, formel:'storeid'}
		]],
		onBeforeOpen:function(p){
	      var queryParams = {
	    		  querystore: '%' + $('#storecode').val() + '%',
	    		  statusid: <%=SysConstant.RecordStatus.VALID %>,
	    		  state : <%=SysConstant.CommonApproveStatus.OK %>
	      };
	      return queryParams;
	    }
	});
}
</script>
<%-- 引入页面尾 --%>
<%@ include file="/pageFloor.jsp"%>